package com.xiaoxi.visitormode.visitor;

import com.xiaoxi.visitormode.composite.Directory;
import com.xiaoxi.visitormode.composite.Entry;
import com.xiaoxi.visitormode.composite.File;

import java.util.Iterator;

/**
 * @Author xiaoxi
 * @ProjectName design_mode
 * @PackageName com.xiaoxi.visitormode.visitor
 * @ClassName ListVisitor
 * @Description TODO
 * @Date 2023/3/16 19:34
 * @Version 1.0
 */
public class ListVisitor implements Visitor {

    private String currentDir = "";

    @Override
    public void visit(File file) {
        System.out.println("当前文件：" + currentDir + "/" + file.getName());
    }

    @Override
    public void visit(Directory directory) {
        System.out.println("访问者，访问目录：" + directory.getName());

        currentDir += "/" + directory.getName();

        Iterator iterator = directory.createIterator();

        while (iterator.hasNext()) {
            Entry entry = (Entry) iterator.next();
            entry.accept(this);
        }

        System.out.println("当前目录：" + currentDir);
    }
}
